package pub.controllers;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import pub.model.Userlogin;
import pub.model.Users;
import pub.services.FaceBS;

import com.dto.UsersDto;

@Controller
@RequestMapping(value = "/face")
public class Face {
	@Resource(name = "faceBSImpl")
	private FaceBS bs;

	/**
	 * face/loginPage
	 * 
	 * @param userLogin
	 * @return
	 * @throws Exception
	 */
	@ResponseBody
	@RequestMapping(value = "/login", method = { RequestMethod.POST })
	public String login(Userlogin userLogin, HttpSession session,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		System.out.println("Face-----login");
		UsersDto userinfo = bs.checkUser(userLogin);
		if (userinfo != null) {
			session.setAttribute("userinfo", userinfo);
			return "success";
		} else {
			return "error";
		}
	}

	@RequestMapping(value = "/loginSuccess", method = { RequestMethod.POST })
	public String loginSuccess() {
		return "main";
	}
}
